package cn.no7player.controller;

import cn.no7player.model.UserEntity;
import cn.no7player.service.UserService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;

@Api(value = "用户接口", description = "用户接口")
@RestController
@RequestMapping("/user")
public class UserController {

    private Logger logger = Logger.getLogger(UserController.class);

    @Autowired
    private UserService userService;


    @ResponseBody
    @RequestMapping(value = "/getUserInfo.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id查询姓名",
            notes = "通过id查询姓名 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public UserEntity getUserInfo(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        UserEntity user = new UserEntity();
        if(user!=null){
            System.out.println("user.getName():"+user.getUserName());
            logger.info("user.getAge():"+user.getAge());
        }
        return user;
    }

    @ResponseBody
    @RequestMapping(value = "/getTel.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id查询姓名",
            notes = "通过id查询姓名 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{id:'1'}", dataType = "String")
    public JSONObject getTel(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        UserEntity user=userService.findById(jsonData);
        JSONObject json = (JSONObject) JSON.toJSON(user);
        return json;
    }
}
